package com.atguigu.bean

import java.text.SimpleDateFormat
import java.util.Date

/**
 * 封装订单详情数据
 *
 * @author WangJX
 * @date 2019/12/2 22:32 
 * @version 1.0
 */
case class SaleDetail(var order_detail_id: String = null,
                      var order_id: String = null,
                      var order_status: String = null,
                      var create_time: String = null,
                      var user_id: String = null,
                      var sku_id: String = null,
                      var user_gender: String = null,
                      var user_age: Int = 0,
                      var user_level: String = null,
                      var sku_price: Double = 0D,
                      var sku_name: String = null,
                      var dt: String = null) {


  def this(orderInfor2: OrderInfor2, orderDetail: OrderDetail) {
    this
    mergeOrderInfo(orderInfor2)
    mergeOrderDetail(orderDetail)
  }

  def mergeOrderInfo(orderInfor2: OrderInfor2) = {
    if (orderInfor2 != null) {
      this.order_id = orderInfor2.id
      this.order_status = orderInfor2.order_status
      this.create_time = orderInfor2.create_time
      this.dt = orderInfor2.create_date
      this.user_id = orderInfor2.user_id
    }
  }

  def mergeOrderDetail(orderDetail: OrderDetail): Unit = {
    if (orderDetail != null) {
      this.order_detail_id = orderDetail.id
      this.sku_id = orderDetail.sku_id
      this.sku_name = orderDetail.sku_name
      this.sku_price = orderDetail.order_price.toDouble
    }
  }

  def mergeUserInfo(userInfo: UserInfo): Unit = {
    if (userInfo != null) {
//      this.user_id = userInfo.id

      //使用生日计算年龄
      val date: Date = new SimpleDateFormat("yyyy-MM-dd").parse(userInfo.birthday)
      val age: Long = date.getTime / 1000L / 60L / 60L / 24L / 365L

      this.user_age = age.toInt
      this.user_gender = userInfo.gender
      this.user_level = userInfo.user_level
    }

  }

}
